﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace dsjsports
{
    static class SynchronizationThread
    {
        private static void ThreadFunction(object Info)
        {
            Queue<SynchronizationInfo> queueInfo =  Info as Queue<SynchronizationInfo>;

            while (true)
            {
                if (queueInfo.Count > 0)
                {
                    SynchronizationInfo i = queueInfo.Dequeue();
                    if (!i.Synchronization())
                    {
                        queueInfo.Enqueue(i);
                        status = "неплучилось =(";
                    }
                }
                else Thread.Sleep(100);
            }
        }

        private static Thread synchronizationThread = new Thread(new ParameterizedThreadStart(ThreadFunction));

        private static string status = "";
        public static string Status
        {
            get { return status; }
        }

        public static void Start(Queue<SynchronizationInfo> queueInfo, ref string adresDataaBase, ref string Status)
        {
            SynchronizationThread.status = Status;
            synchronizationThread.Start(queueInfo);
        }

        internal static void Abort()
        {
            synchronizationThread.Abort();
        }
    }

}
